<template>
  <AvicSplit horizontal>
    <AvicPane size="55">
      <div class="content-wrapper">
        <div class="top-search-box">
          <!-- 高级查询 -->
          <a-form v-bind="layout" ref="formRef" :model="queryForm">
            <a-row :gutter="16">
              <a-col v-bind="colLayout.cols">
                <a-form-item label="用户">
                  <AvicCommonSelect
                    v-model:value="queryForm.demoUserId"
                    type="userSelect"
                    placeholder="请选择用户"
                    :default-show-value="queryForm.demoUserIdAlias"
                    @callback="
                      (result) => {
                        queryForm.demoUserIdAlias = result.names;
                      }
                    "
                  />
                </a-form-item>
              </a-col>
              <a-col v-bind="colLayout.cols">
                <a-form-item label="部门">
                  <AvicCommonSelect
                    v-model:value="queryForm.demoDeptId"
                    type="deptSelect"
                    placeholder="请选择部门"
                    :default-show-value="queryForm.demoDeptIdAlias"
                    @callback="
                      (result) => {
                        queryForm.demoDeptIdAlias = result.names;
                      }
                    "
                  />
                </a-form-item>
              </a-col>
              <a-col v-bind="colLayout.cols">
                <a-form-item label="角色">
                  <AvicCommonSelect
                    v-model:value="queryForm.demoRoleId"
                    type="roleSelect"
                    placeholder="请选择角色"
                    :default-show-value="queryForm.demoRoleIdAlias"
                    @callback="
                      (result) => {
                        queryForm.demoRoleIdAlias = result.names;
                      }
                    "
                  />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="群组">
                  <AvicCommonSelect
                    v-model:value="queryForm.demoGroupId"
                    type="groupSelect"
                    placeholder="请选择群组"
                    :default-show-value="queryForm.demoGroupIdAlias"
                    @callback="
                      (result) => {
                        queryForm.demoGroupIdAlias = result.names;
                      }
                    "
                  />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="岗位">
                  <AvicCommonSelect
                    v-model:value="queryForm.demoPositionId"
                    type="positionSelect"
                    placeholder="请选择岗位"
                    :default-show-value="queryForm.demoPositionIdAlias"
                    @callback="
                      (result) => {
                        queryForm.demoPositionIdAlias = result.names;
                      }
                    "
                  />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="单选">
                  <a-select
                    v-model:value="queryForm.demoRadio"
                    :get-popup-container="(triggerNode) => triggerNode.parentNode"
                    option-filter-prop="children"
                    :show-search="true"
                    :allow-clear="true"
                    placeholder="请选择单选"
                  >
                    <a-select-option v-for="item in lookupList?.PLATFORM_SEX" :key="item.sysLookupTlId" :value="item.lookupCode">
                      {{ item.lookupName }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="单选（按钮样式）">
                  <a-select
                    v-model:value="queryForm.demoRadioButton"
                    :get-popup-container="(triggerNode) => triggerNode.parentNode"
                    option-filter-prop="children"
                    :show-search="true"
                    :allow-clear="true"
                    placeholder="请选择单选（按钮样式）"
                  >
                    <a-select-option v-for="item in lookupList?.PLATFORM_CHECK_TYPE" :key="item.sysLookupTlId" :value="item.lookupCode">
                      {{ item.lookupName }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="下拉">
                  <a-select
                    v-model:value="queryForm.demoSelect"
                    :get-popup-container="(triggerNode) => triggerNode.parentNode"
                    option-filter-prop="children"
                    :show-search="true"
                    :allow-clear="true"
                    placeholder="请选择下拉"
                  >
                    <a-select-option v-for="item in lookupList?.PLATFORM_DEGREE" :key="item.sysLookupTlId" :value="item.lookupCode">
                      {{ item.lookupName }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="密级">
                  <AvicSecretSelect
                    v-model:value="queryForm.secretLevel"
                    :get-popup-container="(triggerNode) => triggerNode.parentNode"
                    option-filter-prop="label"
                    :show-search="true"
                    :allow-clear="true"
                    placeholder="请选择密级"
                  />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="开关">
                  <a-select
                    v-model:value="queryForm.demoSwitch"
                    :get-popup-container="(triggerNode) => triggerNode.parentNode"
                    option-filter-prop="children"
                    :show-search="true"
                    :allow-clear="true"
                    placeholder="请选择开关"
                  >
                    <a-select-option value="Y">有效</a-select-option>
                    <a-select-option value="N">无效</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="日期(起)">
                  <a-date-picker
                    v-model:value="queryForm.demoDateBegin"
                    format="YYYY-MM-DD"
                    value-format="YYYY-MM-DD"
                    placeholder="请选择日期(起)"
                    :disabled-date="(startValue) => proxy.$disabledStartDate(startValue, queryForm.demoDateEnd)"
                  />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="日期(止)">
                  <a-date-picker
                    v-model:value="queryForm.demoDateEnd"
                    format="YYYY-MM-DD"
                    value-format="YYYY-MM-DD"
                    placeholder="请选择日期(止)"
                    :disabled-date="(endValue) => proxy.$disabledEndDate(endValue, queryForm.demoDateBegin)"
                  />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="日期时间(起)">
                  <a-date-picker
                    v-model:value="queryForm.demoDateTimeBegin"
                    format="YYYY-MM-DD HH:mm:ss"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    show-time
                    placeholder="请选择日期时间(起)"
                    :disabled-date="(startValue) => proxy.$disabledStartDate(startValue, queryForm.demoDateTimeEnd)"
                  />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="日期时间(止)">
                  <a-date-picker
                    v-model:value="queryForm.demoDateTimeEnd"
                    format="YYYY-MM-DD HH:mm:ss"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    show-time
                    placeholder="请选择日期时间(止)"
                    :disabled-date="(endValue) => proxy.$disabledEndDate(endValue, queryForm.demoDateTimeBegin)"
                  />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="必填">
                  <a-input v-model:value="queryForm.demoNotnull" placeholder="请输入必填" :allow-clear="true" @pressEnter="handleQuery" />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="编码">
                  <a-input v-model:value="queryForm.demoCode" placeholder="请输入编码" :allow-clear="true" @pressEnter="handleQuery" />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="电话(正则)">
                  <a-input
                    v-model:value="queryForm.demoPhone"
                    placeholder="请输入电话(正则)"
                    :allow-clear="true"
                    @pressEnter="handleQuery"
                  />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="邮件(正则)">
                  <a-input
                    v-model:value="queryForm.demoEmail"
                    placeholder="请输入邮件(正则)"
                    :allow-clear="true"
                    @pressEnter="handleQuery"
                  />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="网址(正则)">
                  <a-input
                    v-model:value="queryForm.demoWebsite"
                    placeholder="请输入网址(正则)"
                    :allow-clear="true"
                    @pressEnter="handleQuery"
                  />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="唯一值">
                  <a-input v-model:value="queryForm.demoUnique" placeholder="请输入唯一值" :allow-clear="true" @pressEnter="handleQuery" />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="弹窗">
                  <a-input
                    v-model:value="queryForm.demoModalSelect"
                    placeholder="请输入弹窗"
                    :allow-clear="true"
                    @pressEnter="handleQuery"
                  />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="背景样式">
                  <a-input
                    v-model:value="queryForm.demoBackgroundColor"
                    placeholder="请输入背景样式"
                    :allow-clear="true"
                    @pressEnter="handleQuery"
                  />
                </a-form-item>
              </a-col>
              <a-col v-show="advanced" v-bind="colLayout.cols">
                <a-form-item label="多行文本">
                  <a-input
                    v-model:value="queryForm.demoTextarea"
                    placeholder="请输入多行文本"
                    :allow-clear="true"
                    @pressEnter="handleQuery"
                  />
                </a-form-item>
              </a-col>
              <a-col v-bind="colLayout.cols" style="margin-left: auto">
                <div class="table-page-search-submitButtons">
                  <a-space>
                    <a-button type="primary" @click="handleQuery">
                      <search-outlined />
                      查询
                    </a-button>
                    <a-button type="primary" ghost @click="resetQuery">
                      <redo-outlined />
                      重置
                    </a-button>
                    <a-button type="link" style="margin: 0" @click="toggleAdvanced">
                      {{ advanced ? '收起' : '展开' }}
                      <up-outlined v-if="advanced" />
                      <down-outlined v-else />
                    </a-button>
                  </a-space>
                </div>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <!-- 表格组件 -->
        <div class="table-wrapper">
          <AvicTable
            ref="demoMainInside"
            table-key="demoMainInside"
            :columns="columns"
            :row-key="(record) => record.id"
            :data-source="list"
            :loading="loading"
            :row-selection="{
              selectedRowKeys: selectedRowKeys,
              onChange: onSelectChange,
              columnWidth: 40,
              fixed: true
            }"
            :page-parameter="queryParam.pageParameter"
            :total="totalPage"
            row-click-selection-type="radio"
            @change="handleTableChange"
            @refresh="getList"
          >
            <template #toolBarLeft>
              <a-space>
                <a-button v-hasPermi="['demoMainInside:add']" title="添加" type="primary" @click="handleAdd">
                  <template #icon>
                    <plus-outlined />
                  </template>
                  添加
                </a-button>
                <a-button
                  v-hasPermi="['demoMainInside:delete']"
                  title="删除"
                  danger
                  :type="selectedRowKeys.length == 0 ? 'default' : 'primary'"
                  :loading="delLoading"
                  @click="handleDelete(selectedRowKeys, '')"
                >
                  <template #icon>
                    <delete-outlined />
                  </template>
                  删除
                </a-button>
                <a-button v-hasPermi="['demoMainInside:import']" title="导入" type="primary" ghost @click="handleImport">
                  <template #icon>
                    <import-outlined />
                  </template>
                  导入
                </a-button>
                <a-button v-hasPermi="['demoMainInside:export']" title="导出" type="primary" ghost @click="handleExport">
                  <template #icon>
                    <export-outlined />
                  </template>
                  导出
                </a-button>
              </a-space>
            </template>
            <template #toolBarRight>
              <a-input-search
                class="opt-btn-commonsearch"
                style="width: 240px"
                placeholder="请输入必填或电话(正则)"
                title="请输入必填或电话(正则)"
                :allow-clear="true"
                @search="handleKeyWordQuery"
              />
            </template>
            <template #bodyCell="{ column, text, record, index }">
              <template v-if="column.dataIndex === 'id'">
                {{ index + 1 + queryParam.pageParameter.rows * (queryParam.pageParameter.page - 1) }}
              </template>
              <template v-else-if="column.dataIndex === 'demoUserIdAlias'">
                <a @click="handleDetail(record)">
                  {{ record.demoUserIdAlias }}
                </a>
              </template>
              <template v-else-if="column.dataIndex === 'demoSwitch'">
                <a-popconfirm
                  :key="list[index].demoSwitch"
                  ok-text="确定"
                  cancel-text="取消"
                  @confirm="changeDemoSwitchStatus(record, index)"
                >
                  <template #title>
                    确认将该数据改为
                    <b>{{ record.demoSwitch === 'Y' ? '无效' : '有效' }}</b>
                    吗?
                  </template>
                  <a-switch :checked="record.demoSwitch === 'Y'" checked-children="有效" un-checked-children="无效" />
                </a-popconfirm>
              </template>
              <template v-else-if="column.dataIndex === 'action'">
                <a-button type="link" class="inner-btn" @click.stop="handleEdit(record.id)">编辑</a-button>
                <a-button
                  v-hasPermi="['demoMainInside:delete']"
                  type="link"
                  class="inner-btn"
                  @click.stop="handleDelete([record.id], 'row')"
                >
                  删除
                </a-button>
              </template>
            </template>
          </AvicTable>
        </div>
      </div>
      <!-- 添加页面弹窗 -->
      <demo-main-inside-add v-if="showAddModal" ref="addModal" @reloadData="getList" @close="showAddModal = false" />
      <!-- 编辑页面弹窗 -->
      <demo-main-inside-edit v-if="showEditModal" ref="editModal" :form-id="formId" @reloadData="getList" @close="showEditModal = false" />
      <!-- 详情页面弹窗 -->
      <demo-main-inside-detail v-if="showDetailModal" ref="detailModal" :form-id="formId" @close="showDetailModal = false" />
      <AvicExcelImport
        v-if="showImportModal"
        :form-data="excelParams"
        title="模板导入"
        import-url="/demo/template/demomaininsides/import-data/v1"
        download-template-url="/demo/template/demomaininsides/download-template/v1"
        @reloadData="getList"
        @close="showImportModal = false"
      />
    </AvicPane>
    <AvicPane>
      <!-- 子表组件 -->
      <demo-sub-inside-manage key="demoSubInsideManage" ref="demoSubInsideManage" :main-id="mainId" />
    </AvicPane>
  </AvicSplit>
</template>

<script lang="ts" setup>
import { useLookup } from '@/utils/hooks/useLookup';
// 引入模块DTO
import type { DemoMainInsideDto } from '@/api/avic/demo/DemoMainInsideApi';
// 引入模块API
import { listDemoMainInsideByPage, delDemoMainInside, updateDemoSwitch, exportExcel } from '@/api/avic/demo/DemoMainInsideApi';
// 引入添加页面组件
import DemoMainInsideAdd from './DemoMainInsideAdd.vue';
// 引入编辑页面组件
import DemoMainInsideEdit from './DemoMainInsideEdit.vue';
// 引入详情页面组件
import DemoMainInsideDetail from './DemoMainInsideDetail.vue';
import DemoSubInsideManage from '../demosubinside/DemoSubInsideManage.vue'; // 引入子表页面组件
const { proxy } = getCurrentInstance();
const layout = {
  labelCol: { flex: '120px' },
  wrapperCol: { flex: '1' }
};
const colLayout = proxy.$colLayout4; // 页面表单响应式布局对象
const columns = [
  {
    title: '序号',
    dataIndex: 'id',
    ellipsis: true,
    width: 60,
    align: 'center',
    fixed: 'left'
  },
  {
    title: '用户',
    dataIndex: 'demoUserIdAlias',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    customHeaderCell() {
      return {
        ['class']: 'required-table-title'
      };
    },
    align: 'left'
  },
  {
    title: '部门',
    dataIndex: 'demoDeptIdAlias',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '角色',
    dataIndex: 'demoRoleIdAlias',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '群组',
    dataIndex: 'demoGroupIdAlias',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '岗位',
    dataIndex: 'demoPositionIdAlias',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '单选',
    dataIndex: 'demoRadioName',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    align: 'center'
  },
  {
    title: '单选（按钮样式）',
    dataIndex: 'demoRadioButtonName',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    align: 'center'
  },
  {
    title: '复选',
    dataIndex: 'demoCheckboxName',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '下拉',
    dataIndex: 'demoSelectName',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    align: 'center'
  },
  {
    title: '下拉多选',
    dataIndex: 'demoSelectMultipleName',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '密级',
    dataIndex: 'secretLevelName',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    customHeaderCell() {
      return {
        ['class']: 'required-table-title'
      };
    },
    align: 'center'
  },
  {
    title: '开关',
    dataIndex: 'demoSwitch',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    align: 'center'
  },
  {
    title: '小数',
    dataIndex: 'demoNumber',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    customRender: (text) => proxy.$formatZero(text.value, 2),
    align: 'right'
  },
  {
    title: '整数',
    dataIndex: 'demoInteger',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    align: 'right'
  },
  {
    title: '日期',
    dataIndex: 'demoDate',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    align: 'center'
  },
  {
    title: '日期时间',
    dataIndex: 'demoDateTime',
    ellipsis: true,
    minWidth: 120,
    resizable: true,
    align: 'center'
  },
  {
    title: '必填',
    dataIndex: 'demoNotnull',
    ellipsis: true,
    sorter: true,
    minWidth: 120,
    resizable: true,
    customHeaderCell() {
      return {
        ['class']: 'required-table-title'
      };
    },
    align: 'left'
  },
  {
    title: '编码',
    dataIndex: 'demoCode',
    ellipsis: true,
    sorter: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '电话(正则)',
    dataIndex: 'demoPhone',
    ellipsis: true,
    sorter: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '邮件(正则)',
    dataIndex: 'demoEmail',
    ellipsis: true,
    sorter: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '网址(正则)',
    dataIndex: 'demoWebsite',
    ellipsis: true,
    sorter: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '唯一值',
    dataIndex: 'demoUnique',
    ellipsis: true,
    customHeaderCell() {
      return {
        ['class']: 'required-table-title'
      };
    },
    minWidth: 120,
    resizable: true,
    sorter: true,
    align: 'left'
  },
  {
    title: '弹窗',
    dataIndex: 'demoModalSelect',
    ellipsis: true,
    sorter: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '背景样式',
    dataIndex: 'demoBackgroundColor',
    ellipsis: true,
    sorter: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '富文本',
    dataIndex: 'demoRichtext',
    ellipsis: true,
    sorter: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '多行文本',
    dataIndex: 'demoTextarea',
    ellipsis: true,
    sorter: true,
    minWidth: 120,
    resizable: true,
    align: 'left'
  },
  {
    title: '操作',
    dataIndex: 'action',
    ellipsis: true,
    width: 120,
    fixed: 'right'
  }
];
const queryForm = ref<DemoMainInsideDto>({});
const queryParam = reactive({
  // 请求表格数据参数
  pageParameter: {
    page: 1, // 页数
    rows: proxy.$settings.table.pageSize || 20 // 每页条数
  },
  searchParams: {
    ...queryForm
  },
  keyWord: ref(''), // 快速查询数据
  sidx: null, // 排序字段
  sord: null // 排序方式: desc降序 asc升序
});
const showAddModal = ref(false); // 是否展示添加弹窗
const showEditModal = ref(false); // 是否展示编辑弹窗
const showDetailModal = ref(false); // 是否展示详情弹窗
const showImportModal = ref(false); // 是否展示导入弹窗
const excelParams = ref({ tableName: 'demoMainInside' }); // 必填参数tableName全局唯一，与tableKey保持一致
const advanced = ref(false); // 高级搜索 展开/关闭
const list = ref([]); // 表格数据集合
const formId = ref(''); // 当前行数据id
const selectedRowKeys = ref([]); // 选中数据主键集合
const selectedRows = ref([]); // 选中行集合
const loading = ref(false);
const delLoading = ref(false);
const totalPage = ref(0);
const { lookupList } = useLookup(['PLATFORM_SEX', 'PLATFORM_CHECK_TYPE', 'PLATFORM_DEGREE']);

const mainId = computed(() => {
  if (selectedRowKeys.value.length === 1) {
    return selectedRowKeys.value[0];
  }
  return '';
});

onMounted(() => {
  // 加载表格数据
  getList();
});

/** 查询数据  */
function getList() {
  selectedRowKeys.value = []; // 清空选中
  selectedRows.value = [];
  list.value = [];
  loading.value = true;
  listDemoMainInsideByPage(queryParam)
    .then((response) => {
      list.value = response.data.result;
      totalPage.value = response.data.pageParameter.totalCount;
      // 设置表格初始选中项
      if (list.value.length > 0) {
        selectedRowKeys.value = [list.value[0].id];
      } else {
        selectedRowKeys.value = [];
      }
      loading.value = false;
    })
    .catch(() => {
      list.value = [];
      totalPage.value = 0;
      loading.value = false;
    });
}
/** 高级搜索按钮操作 */
function handleQuery() {
  queryParam.searchParams = queryForm.value;
  queryParam.keyWord = '';
  queryParam.pageParameter.page = 1;
  getList();
}
/** 高级查询重置按钮操作  */
function resetQuery() {
  queryForm.value = {};
  handleQuery();
}
/** 高级查询 展开/收起 */
function toggleAdvanced() {
  advanced.value = !advanced.value;
}
/** 快速查询逻辑 */
function handleKeyWordQuery(value) {
  queryParam.keyWord = value;
  queryParam.pageParameter.page = 1;
  getList();
}
/** 添加 */
function handleAdd() {
  showAddModal.value = true;
}
/** 编辑 */
function handleEdit(id) {
  formId.value = id;
  showEditModal.value = true;
}
/** 详情 */
function handleDetail(record) {
  formId.value = record.id;
  showDetailModal.value = true;
}
/** 导入 */
function handleImport() {
  showImportModal.value = true;
}
/** 导出 */
function handleExport() {
  proxy.$confirm({
    title: '确认导出数据吗?',
    okText: '确定',
    cancelText: '取消',
    centered: true,
    onOk: () => {
      loading.value = true;
      queryParam.searchParams = queryForm.value;
      exportExcel(queryParam).then(() => {
        loading.value = false;
        proxy.$message.info('导出成功！');
      });
    }
  });
}
/** 删除 */
function handleDelete(ids, type) {
  if (ids.length === 0) {
    proxy.$message.warning('请选择要删除的数据！');
    return;
  }
  proxy.$confirm({
    title: `确认要删除${type === 'row' ? '当前行的' : '已选数据及关联的子表'}数据吗?`,
    okText: '确定',
    cancelText: '取消',
    centered: true,
    onOk: () => {
      delLoading.value = true;
      delDemoMainInside(ids)
        .then((res) => {
          if (res.success) {
            proxy.$message.success('删除成功！');
            // 清空选中
            selectedRowKeys.value = [];
            selectedRows.value = [];
            getList();
          }
          delLoading.value = false;
        })
        .catch(() => {
          delLoading.value = false;
        });
    }
  });
}
/** 改变开关状态 */
function changeDemoSwitchStatus(record, index) {
  const tip = record.demoSwitch === 'Y' ? '无效' : '有效';
  const updateValue = record.demoSwitch === 'Y' ? 'N' : 'Y';
  updateDemoSwitch(record.id, updateValue).then((res) => {
    if (res.success) {
      list.value[index].demoSwitch = updateValue;
      proxy.$message.success(`${tip}成功！`);
    }
  });
}
/** 勾选复选框时触发 */
function onSelectChange(rowKeys, rows) {
  selectedRowKeys.value = rowKeys;
  selectedRows.value = rows;
}
/** 表头排序 */
function handleTableChange(pagination, _filters, sorter) {
  queryParam.pageParameter.page = pagination.current;
  queryParam.pageParameter.rows = pagination.pageSize;
  if (proxy.$objIsNotBlank(sorter.field)) {
    queryParam.sidx = sorter.field;
    queryParam.sord = sorter.order === 'ascend' ? 'asc' : 'desc'; // 排序方式: desc降序 asc升序
  }
  getList();
}
</script>
